<template>
  <div class="menu-container">
    <div class="menu-box">
      <div class="menu-title-img">
        <!-- <div @click="gotoLogin" v-if="!isLogin">LOG IN</div> -->
        <!-- <div v-if="isLogin">{{ userInfo.nickName }}</div> -->
      </div>
      <div class="menu-title">
        <img src="../static/slider/logo2.png" alt="" />
      </div>
      <div class="price-box">
        <div class="price-title">PACKAGE PRICING LIST</div>
        <div class="price-list" v-for="item in menuPriceList" :key="item.id">
          <div class="price-info">
            <div class="price-name">{{ item.name }}</div>
            <div>
              <span>{{ item.meals }}</span
              >MEALS
            </div>
            <div>
              NETT PRING:<span>${{ item.nettPring }}</span>
            </div>
          </div>
          <div class="price-includes">INCLUDES:</div>
          <div class="includes-list">
            <div class="includes-item">
              <span class="item-num">1</span>
              <div class="item-title">
                {{ item.orderFoodIncludesVoList.deliveries }} Deliveries
              </div>
            </div>
            <div class="includes-item">
              <span class="item-num">2</span>
              <div class="item-title">Personal Training</div>
              <div class="item-price">
                ${{ item.orderFoodIncludesVoList.personalTrainingPrice }}
              </div>
              <div class="item-price-person">
                <span
                  >${{
                    item.orderFoodIncludesVoList
                      .personalTrainingPreferentialPrice
                  }}</span
                >/Lesson
              </div>
              <div
                class="free"
                v-if="item.orderFoodIncludesVoList.foodSession != 0"
              >
                Free {{ item.orderFoodIncludesVoList.foodSession }} Sessions
              </div>
            </div>
            <div class="includes-item">
              <span class="item-num">3</span>
              <div class="item-title">Group Class</div>
              <div class="item-price">
                ${{ item.orderFoodIncludesVoList.groupClassPrice }}
              </div>
              <div class="item-price-person">
                <span
                  >${{
                    item.orderFoodIncludesVoList.groupClassPreferentialPrice
                  }}</span
                >/Lesson
              </div>
              <div
                class="free"
                v-if="item.orderFoodIncludesVoList.foodLesson != 0"
              >
                Free {{ item.orderFoodIncludesVoList.foodLesson }} Lessons
              </div>
            </div>
          </div>
          <div class="price-tips">
            <div>
              <img src="../static/slider/flower.png" alt="" />{{
                item.introduce
              }}
            </div>
            <div class="selected-btn">
              <button @click="selectMenu(item)" v-if="!item.isSelected">
                SELECT
              </button>
              <img
                class="selected-img"
                src="../static/slider/selected.png"
                alt=""
                v-if="item.isSelected"
                @click="selectMenu(item)"
              />
            </div>
          </div>
        </div>
        <div class="require-box">
          <div class="title-btn">
            <!-- <div></div> -->
            <div class="re-title">Terms & Conditions</div>
          </div>
          <div class="require-body">
            <div class="terms">
              <div class="terms-title">EXPIRY DATES</div>
              <div class="terms-dates">
                <div class="dates-icon">
                  <img src="../static/slider/termsIcon.png" alt="" />
                </div>
                <div class="dates-info">
                  <div class="dates-item">
                    <div><span>10</span> Meals</div>
                    <div><span>2</span> weeks</div>
                  </div>
                  <div class="dates-item">
                    <div><span>20</span> Meals</div>
                    <div><span>4</span> weeks</div>
                  </div>
                  <div class="dates-item">
                    <div><span>40</span> Meals</div>
                    <div><span>8</span> weeks</div>
                  </div>
                </div>
                <div></div>
              </div>
            </div>
            <div class="conditions">
              <div>
                Ordering must be made at least 3 days in advance (excluding
                weekend's and public holidays).
              </div>
              <div>Price excludes delivery.</div>
              <div>
                Regular meal orders are only available on weekdays. For weekend
                and public holiday orders, please contact customer service.
              </div>
            </div>
          </div>
        </div>
        <div class="re-btn">
          <div @click="orderNow">NEXT</div>
        </div>
      </div>
    </div>
    <div class="menu">
      <div class="hamburger menu" @click="clickMenu">
        <div class="bar" :class="menuClicked ? 'animate' : ''"></div>
      </div>
      <div class="uvnav down" @click="next"></div>
      <div class="uvnav up" @click="prev"></div>
      <!-- <a id="mainlogo" href="#" v-if="currentIndex == 1"><img src="../static/slider/LOGO.png" /> </a> -->
      <a class="cnav tr gohome" href="#" style="" v-if="menuClicked">GO BACK</a>
      <a
        class="cnav tr gohome"
        style="cursor: pointer"
        @click="toLogin"
        v-if="!menuClicked && !isLogin"
        >LOG IN</a
      >
      <a
        class="cnav tr login-text"
        @click="toPerson"
        v-if="!menuClicked && isLogin"
      >
        <div>{{ userInfo.nickName }}</div>
        <img src="../static/slider/avatar.png" alt="" />
      </a>
      <a class="cnav bl contact zt-more" href="#">CONTACT</a>
      <a class="cnav br awards zt-more" href="#">AWARDS</a>
      <div
        class="popup-box"
        :class="{ menuActive: menuClicked }"
        ref="popup_box"
      >
        <div class="popup-body" v-if="menuClicked">
          <div>FOOD</div>
          <div>CHEF</div>
          <div>PLACE</div>
          <div>STORY</div>
          <div>BOOKINGS</div>
          <div>EVENTS</div>
        </div>
        <div class="concat-box" v-if="menuClicked">
          <div class="concat-img">
            <div class="F1"></div>
            <div class="W1"></div>
            <div class="Y1"></div>
          </div>
          <div class="concat-text">
            PRESS ACCESS DUAL BY FIT ISLAND PORTFOLIO
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { MessageBox, Message } from "element-ui";

export default {
  name: "MenuPrice",
  data() {
    return {
      isLogin: false,
      userInfo: {},
      menuClicked: false,
      currentData: {},
      menuPriceList: [],
    };
  },
  created() {
    this.checkedLoginStatus();
    this.getPackageList();
  },
  methods: {
    // 获取套餐数据
    getPackageList() {
      let queryForm = {
        pageNum: 1,
        pageSize: 3,
      };
      this.$login.getOrderFoodPage(queryForm).then((res) => {
        if (res && res.code === "00000") {
          this.menuPriceList = res.data;
          this.menuPriceList.forEach((ele) => {
            this.$set(ele, "isSelected", false);
          });
          console.log(this.menuPriceList, "套餐");
        }
      });
    },
    checkedLoginStatus() {
      if (this.$user.getToken()) {
        this.isLogin = true;
        this.userInfo = JSON.parse(this.$user.getUserInfo());
      }
    },
    toPerson() {
      this.$router.push({
        name: "PersonCenter",
      });
    },
    toLogin() {
      this.$router.push({
        name: "Login",
      });
    },
    orderNow() {
      if (!this.isLogin) {
        MessageBox.confirm(
          "You have not logged in yet. Please log in and submit your order!",
          "SYSTEM PROMPT",
          {
            confirmButtonText: "Log In Again",
            cancelButtonText: "CANCEL",
            type: "warning",
          }
        ).then(() => {
          location.href = "/#/Login";
        });
        return;
      }
      if (JSON.stringify(this.currentData) == "{}") {
        this.$message({
          message: "Please select the package before placing an order",
          type: "warning",
        });
        return;
      }
      this.$router.push({
        name: "Order",
        params: {
          orderInfo: JSON.stringify(this.currentData),
        },
      });
      // let queryForm = {
      //   userId: this.userInfo.id,
      //   foodId: this.currentData.id,
      // };
      // this.$login.setPlaceOrder(queryForm).then((res) => {
      //   if (res && res.code === "00000") {
      //     Message({
      //       message: "Successfully submitted order!",
      //       type: "success",
      //       duration: 2 * 1000,
      //     });
      //     this.$router.push({
      //       name: "Order",
      //       params: {
      //         orderInfo: JSON.stringify(this.currentData),
      //       },
      //     });
      //   }
      // });
    },
    selectMenu(item) {
      this.menuPriceList.forEach((ele) => {
        ele.isSelected = false;
      });
      item.isSelected = !item.isSelected;
      if (item.isSelected) {
        this.currentData = item;
      }
    },
    gotoBooking() {
      this.$router.push({
        name: "Booking",
      });
    },
    async prev() {
      // this.$router.push({
      //   name: "MENU",
      // });
    },
    async next() {
      this.$router.push({
        name: "MENU",
      });
    },
    clickMenu() {
      if (!this.menuClicked) {
        console.log(this.menuClicked, "this.menuClicked");
        this.$refs.popup_box.style.zIndex = 888;
        this.$refs.popup_box.style.width = "100vw";
      } else {
        this.$refs.popup_box.style.width = 0;
      }
      this.menuClicked = !this.menuClicked;
    },
    gotoLogin() {
      this.$router.push({
        name: "Login",
      });
    },
    handleIngredients() {
      this.offeringsList.forEach((item) => {
        item.ingredients = item.ingredients.split(",");
        console.log(item.ingredients, "item.ingredients");
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.menu-container {
  background-color: rgb(200, 81, 1);
  width: 100vw;
  min-height: 100vh;
  /* padding: 0 20% 0 20%; */
  display: flex;
  justify-content: center;
}

.menu-box {
  background-color: #fff;
  width: 60vw;
  min-height: 100%;
  position: relative;

  .menu-title-img {
    height: 18vh;
    width: 100%;
    // margin-bottom: 5vh;
    position: relative;
    > div {
      position: absolute;
      top: 5vh;
      right: 2vw;
      color: #a98c48;
      font-size: 1vw;
      cursor: pointer;
    }
  }
  .menu-title {
    width: 16vw;
    height: 18vh;
    position: absolute;
    top: 6vh;
    right: 1%;

    > img {
      width: 100%;
      height: 100%;
    }
  }
}

.require-box {
  .title-btn {
    display: flex;
    // flex-direction: row-reverse;
    justify-content: space-between;
    > div {
      flex: 1;
    }
    .re-title {
      font-size: 1.2vw;
      font-weight: bolder;
      color: #646464;
      text-align: center;
    }
    .re-btn {
      display: flex;
      justify-content: end;
      align-items: center;
      > div {
        background: linear-gradient(to bottom, #dcbe6e 5%, #aa8c46 100%);
        font-size: 0.7vw;
        color: #fff;
        padding: 0.5vh 2.5vw;
        font-weight: bold;
        border-radius: 25px;
        cursor: pointer;
        user-select: none;
      }
      > div:active {
        background: linear-gradient(to bottom, #fff 5%, #fff 100%);
        color: #dcbe6e;
      }
    }
  }
  .require-body {
    margin-top: 1vh;
    display: flex;
    border: 1px solid #c85000;
    justify-content: space-between;
    padding: 1vh 1vw;
    margin-bottom: 2vh;
    color: #646464;
    > div {
      width: 48%;
    }
    .terms {
      .terms-title {
        text-align: center;
        font-size: 0.8vw;
        font-weight: bold;
        color: #c85000;
      }
      .terms-dates {
        border-bottom: 1px solid #c85000;
        border-top: 1px solid #c85000;
        border-right: 1px solid #c85000;
        padding: 1vh 0.5vw 0 0.5vw;
        display: flex;
        justify-content: space-between;
        align-items: center;
        > div {
          flex: 1;
        }

        .dates-icon {
          display: flex;
          justify-content: center;
          align-items: center;
          > img {
            width: 3.3vw;
            height: 5vh;
          }
        }

        .dates-info {
          font-size: 0.8vw;
          .dates-item {
            display: flex;
            justify-content: space-between;
            margin-bottom: 1vh;
            div > span {
              font-weight: bold;
            }
          }
        }
      }
    }
    .conditions {
      font-size: 0.7vw;
      font-family: "Times New Roman", Times, serif;
      display: flex;
      justify-content: end;
      flex-direction: column;
      > div {
        // white-space: nowrap;
        line-height: 2vh;
        font-style: italic;
        text-decoration: underline;
      }
    }
  }
}

.price-box {
  padding: 0 3%;

  .price-title {
    text-align: center;
    font-size: 1.2vw;
    font-weight: bolder;
    color: #646464;
  }

  .price-list {
    margin-top: 1.5vh;
    margin-bottom: 3vh;
    color: #646464;

    .price-info {
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-top: 1px solid #c85000;
      border-bottom: 1px solid #c85000;
      border-left: 1px solid #c85000;
      padding: 0.5vh 1vw;
      font-size: 0.9vw;
      div {
        flex: 1;
      }
      div:nth-child(2) {
        text-align: center;
      }
      div:nth-child(3) {
        text-align: right;
      }
      div > span {
        font-weight: bold;
        margin: 0 0.3vw;
      }

      .price-name {
        color: #c85000;
      }
    }

    .price-includes {
      padding: 0.5vh 1vw;
      font-size: 0.8vw;
      font-weight: bold;
      color: #a98c48;
      border-right: 1px solid #646464;
    }

    .includes-list {
      padding: 1vh 1vw 0 1vw;
      border-bottom: 1px solid #646464;
      border-top: 1px solid #646464;
      border-left: 1px solid #646464;

      .includes-item {
        display: flex;
        align-items: center;
        margin-bottom: 1vh;
        font-size: 0.9vw;

        .item-num {
          background-color: #c85000;
          color: #fff;
          width: 1vw;
          height: 1vw;
          border-radius: 25px;
          align-items: center;
          display: flex;
          justify-content: center;
          font-size: 0.7vw;
          font-weight: bolder;
          margin-right: 0.5vw;
        }
        .item-title {
          flex: 3;
        }
        .item-price {
          flex: 1;
          text-decoration: line-through;
        }
        .item-price-person {
          flex: 4;

          > span {
            font-weight: bold;
          }
        }
        .free {
          flex: 2;
        }
      }
    }
    .price-tips {
      font-size: 0.8vw;
      padding: 0.5vh 1vw;
      border-bottom: 1px solid #646464;
      border-right: 1px solid #646464;
      display: flex;
      align-items: center;
      justify-content: space-between;

      div > img {
        width: 1vw;
        height: 1vw;
        margin-right: 0.2vw;
      }
      .selected-btn > button {
        background: linear-gradient(to bottom, #dcbe6e 5%, #aa8c46 100%);
        font-size: 0.7vw;
        color: #fff;
        padding: 0.5vh 2.5vw;
        font-weight: bold;
        border-radius: 25px;
        cursor: pointer;
        user-select: none;
        border: none;
      }

      .selected-btn > img {
        width: 7.1vw;
        height: 2.5vh;
      }
    }
  }
}
.re-btn {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 2vh;
  > div {
    background: linear-gradient(to bottom, #dcbe6e 5%, #aa8c46 100%);
    font-size: 0.7vw;
    color: #fff;
    padding: 0.5vh 2.5vw;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    user-select: none;
  }
  > div:active {
    background: linear-gradient(to bottom, #fff 5%, #fff 100%);
    color: #dcbe6e;
  }
}
.cnav.tr {
  top: 30px;
  right: 30px;
}
.cnav.tr img {
  cursor: pointer;
  width: 2.5vw;
  height: 2.5vw;
}
.login-text {
  display: flex;
  align-items: center;
  font-size: 1vw;
  cursor: pointer;

  img {
    margin-left: 0.4vw;
  }
  /* flex-direction: column; */
}
</style>